package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.ExceptionDialog;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

public class ExceptionDialogActions {
    static{
        PropertyFactory.regist(ExceptionDialog.class, "introTextProperty", o -> {
            ExceptionDialog obj = (ExceptionDialog) o;
            return obj.introTextProperty();
        });
        PropertyFactory.regist(ExceptionDialog.class, "exceptionProperty", o -> {
            ExceptionDialog obj = (ExceptionDialog) o;
            return obj.exceptionProperty();
        });
    }

    public static void init(ExceptionDialog node, Thing thing, ActionContext actionContext) {
        DialogActions.init(node, thing, actionContext);

        Exception exception = JavaFXUtils.getObject(thing, "exception", actionContext);
        if (exception != null) {
            node.setException(exception);
        }

        String introText = JavaFXUtils.getObject(thing, "introText", actionContext);
        if (introText != null) {
            node.setIntroText(introText);
        }

    }

    public static ExceptionDialog create(ActionContext actionContext) {
        Thing self = actionContext.getObject("self");
        ExceptionDialog node = new ExceptionDialog();
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for (Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }

}